Poly Os Manager
open class PolyOsManager( context: Context, polyAppCallBacks: IPolyAppCallBacks?, polyOsListener: PolyOsListener?) : IPolyOsManager
Content copied to clipboard
PolyOsManager exposes the api to communicate between a client application and PolyOs.
Usage:
//Create an instance of PolyOsPlusManager
polyOsManager = PolyOsManager(context);
//Notify PolyOS when app state changes
polyOsManager.notifyAppStateChanged(AppState(inCall = true))
//Access services through the suspend function. Suspends until connected with polyos
val isMuted = polyOsManager { audioService.isMicrophoneMuted }
//Mute microphone
polyOsManager { audioService.muteMicrophone(true)}
//register listeners whenever polyos gets connected/reconnected
polyOsManager.runWhenConnected {
//Register for audio notifications
audioService.registerAudioListener(audioListener)
//Register for messages
roomService.registerRoomListener(roomListener)
}
Content copied to clipboard
Samples
import android.content.Context
import com.poly.polyos.AppState
import com.poly.polyos.PolyOsManager
import com.poly.polyos.audio.IPolyAudioListener
import com.poly.polyos.room.IPolyRoomListener
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
fun main() {
//sampleStart
/**
* Sample usages for [PolyOsManager]
*/
class PolyOsSample {
/**
* Sample usage of [PolyOsManager]
*/
suspend fun samplePolyOsManagerCreation(context: Context) {
//Create PolyOsManager using context.
val polyOsManager = PolyOsManager(context)
//@see sampleNotifyOnAppStateChange of how to notify of app state changes
}
/**
* Sample usage of how to listen for connection state changes
*/
suspend fun samplePolyOsManagerConnectionStateListen(context: Context, scope: CoroutineScope) {
//Create PolyOsManager using context.
val polyOsManager = PolyOsManager(context)
println("Connected ${polyOsManager.connectedState.value}")
scope.launch {
polyOsManager.connectedState.collect { connected ->
println("Connected $connected")
}
}
}
/**
* Notify polyos on app state changes like in call, content etc
*/
suspend fun sampleNotifyOnAppStateChange(polyOsManager: PolyOsManager) {
val currentAppState = AppState()
//When in call, notify polyOs
currentAppState.inCall = true
polyOsManager.notifyAppStateChanged(currentAppState)
//When out of call, notify polyOs
currentAppState.inCall = false
polyOsManager.notifyAppStateChanged(currentAppState)
}
/**
* Sample polyos api call using helper function that suspends until connected
*/
suspend fun sampleAudioApi(polyOsManager: PolyOsManager) {
//get mute state
//call through suspend helper. suspends until connected with service
val isMuted = polyOsManager { audioService.isMicrophoneMuted }
//Mute audio
polyOsManager { audioService.muteMicrophone(true) }
}
/**
* Sample polyos api call using helper function that suspends until connected
*/
fun sampleRunWhenConnected(polyOsManager: PolyOsManager, audioListener: IPolyAudioListener, roomListener: IPolyRoomListener) {
//register listeners whenever polyos gets connected/reconnected
polyOsManager.runWhenConnected {
//Register for audio notifications
audioService.registerAudioListener(audioListener)
//Register for messages
roomService.registerRoomListener(roomListener)
}
//Perform a one time task on first connection
polyOsManager.runWhenConnected (oneshot = true) {
val muted = audioService.isMicrophoneMuted
println( "Audio is muted: $muted")
}
}
}
//sampleEnd
}Parameters
context
Context to use
poly App Call Backs
The IPolyAppCallBacks so that PolyOs can query/listen to app changes
poly Os Listener
The PolyOsListener to know connected state and any other call backs
Constructors
Link copied to clipboard
Creates an instance of PolyOsManager.
Link copied to clipboard
fun PolyOsManager( context: Context, polyAppCallBacks: IPolyAppCallBacks?, polyOsListener: PolyOsListener?)
Content copied to clipboard
Creates an instance of PolyOsManager.
Functions
Link copied to clipboard
Notifies polyos that the app state has changed.
Link copied to clipboard
fun runWhenConnected( name: String? = null, oneshot: Boolean = false, task: PolyOsManager.() -> Unit)
Content copied to clipboard
Runs the given task if/when connected.
Link copied to clipboard
Sets whether to target the calls to primary or the local device.
Properties
Link copied to clipboard
Returns IPolyAnalyticsService if connected.
Link copied to clipboard
Returns IPolyAudioService if connected.
Link copied to clipboard
Returns IPolyCameraService if connected.
Link copied to clipboard
Returns IPolyRoomService if connected.
Link copied to clipboard
Returns IPolySettingsService if connected.
Link copied to clipboard
Returns IPolySystemService if connected.